package org.zoomdev.zoom.dao.alias.impl;


import org.zoomdev.zoom.common.utils.NameCaseConverter;
import org.zoomdev.zoom.dao.alias.NameMapping;

/**
 * 使用前缀来修改名称的策略
 * <p>
 * PrefixAliasPolicy policy = new PrefixAliasPolicy("NAME_");
 * assertTrue(policy.getAlias("NAME_ID").equals("id"));
 */
public final class PrefixNameMapping implements NameMapping {

    private final String prefix;

    public PrefixNameMapping(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public String getMapping(String column) {
        if (column.startsWith(prefix)) {
            column = column.substring(prefix.length());
        }

        return NameCaseConverter.toCamelCase(column);
    }


}
